package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.service.CarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Carousel)表控制层
 *
 * @author makejava
 * @since 2024-02-29 21:02:30
 */
@RestController
@RequestMapping("/carousel")
public class CarouselController {
    /**
     * 服务对象
     */
    @Autowired
    private CarouselService carouselService;


    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("/deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        carouselService.deleteByIds(ids);
        return Result.success("删除成功！");
    }

    /**
     * 添加公告
     *
     * @param carousel
     * @return
     */
    @PostMapping("/addCarousel")
    public Result addCarousel(@RequestBody Carousel carousel) {
        carouselService.addCarousel(carousel);
        return Result.success();
    }

    /**
     * 条件查询 分页
     *
     * @param currentPage
     * @param pageSize
     * @param title
     * @param detail
     * @param startTime
     * @param endTime
     * @param status
     * @return
     */
    @GetMapping("/selectByManyConditionInPage")
    public Result selectByManyConditionInPage(
            @RequestParam("currentPage") Integer currentPage,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam("title") String title,
            @RequestParam("detail") String detail,
            @RequestParam("startTime") String startTime,
            @RequestParam("endTime") String endTime,
            @RequestParam("status") Integer status) {
        return Result.success(carouselService.selectByManyConditionInPage(currentPage, pageSize, title, detail, startTime, endTime, status));
    }


    @GetMapping("/selectByManyConditionNoStatusInPage")
    public Result selectByManyConditionNoStatusInPage(
            @RequestParam("currentPage") Integer currentPage,
            @RequestParam("pageSize") Integer pageSize,
            @RequestParam("title") String title,
            @RequestParam("detail") String detail,
            @RequestParam("startTime") String startTime,
            @RequestParam("endTime") String endTime) {
        return Result.success(carouselService.selectByManyConditionNoStatusInPage(currentPage, pageSize, title, detail, startTime, endTime));
    }


    /**
     * 获取所有的系统公告信息
     *
     * @return
     */
    @GetMapping("/selectAll")
    public Result selectAll() {
        return Result.success(carouselService.selectAll());
    }


    /**
     * 获取最新的五条系统公告信息
     *
     * @return
     */
    @GetMapping("/latest")
    public Result selectLatest() {
        return Result.success(carouselService.selectLatest());
    }


    /**
     * 分页查询
     *
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/selectByPage")
    public Result selectByPage(@RequestParam("currentPage") Integer currentPage,
                               @RequestParam("pageSize") Integer pageSize) {
        return Result.success(carouselService.selectByPage(currentPage, pageSize));
    }


    /**
     * 根据ID删除系统公告信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        carouselService.deleteById(id);
        return Result.success("删除成功!");
    }


    /**
     * 更新公告信息
     *
     * @param carousel
     * @return
     */
    @PutMapping("/updateById")
    public Result updateById(@RequestBody Carousel carousel) {
        carouselService.updateById(carousel);
        return Result.success("更新成功！");
    }


    /**
     * 更新轮播图的状态
     *
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status) {
        carouselService.updateStatus(id, status);
        return Result.success("更新成功！");
    }
}

